package cn.bgs.controller;


import cn.bgs.pojo.Animal;
import cn.bgs.service.AnimalService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class AnimalController {

    @Autowired private AnimalService animalService;

    @RequestMapping("/findAll")
    public String findAll(Model m, @RequestParam(defaultValue = "1") Integer pageNum){

       Integer pageSiz=3;

       PageInfo<Animal> list= animalService.findAll(pageNum,pageSiz);

       m.addAttribute("p",list);

       return "quan";

    }


    @RequestMapping("/updateById")
    public String updateById(Model m,Integer id){

        Animal animal=animalService.selectByPrimaryKey(id);

        m.addAttribute("list",animal);

        return "update";


    }

    @RequestMapping("/update")
    public String update(Animal record){
        int ff=animalService.updateByPrimaryKeySelective(record);

        return "redirect:/findAll";

    }



}
